package com.eian.boot.mybatis.core.listener;

import com.eian.boot.mybatis.core.model.BaseEntity;
import com.mybatisflex.annotation.InsertListener;

import java.time.LocalDateTime;

/**
 * @author alex.meng
 * @createTime 2025-09-04 15:39
 * @description 插入时数据填充
 **/
public abstract class AbstractFieldInsertListener implements InsertListener {
    @Override
    public final void onInsert(Object o) {
        if (o instanceof BaseEntity entity) {
            entity.setCreatedAt(LocalDateTime.now());
            entity.setCreatedBy(getOperatorId());
        }
    }

    protected abstract Long getOperatorId();
}
